package com.guapi.service;

import com.guapi.dao.Menu;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service

public class MenuService extends SelfBaseService<Menu> {

    public List<Menu> packageMenu(List<Menu> menuList) {
        ArrayList<Menu> fatherList = new ArrayList<>();
        menuList.forEach(menu -> {
            if (menu.getParentId().equals("top")) {
                fatherList.add(menu);
            }
        });
        fatherList.forEach(menu -> {
            ArrayList<Menu> children = new ArrayList<>();
            menuList.forEach(menu1 -> {
                if (menu1.getParentId().equals(menu.getId().toString())) {
                    children.add(menu1);
                }
            });
            menu.setChildren(children);
        });
        return fatherList;
    }

}
